package com.softtek.unitTest;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Iterator;

import com.softtek.webbrowser.UrlManager;
import com.softtek.history.History;
/**
 * Test clas for URLManager {@link URLManager}
 * @author hector.nevarez
 * @see URLManager History
 */
public class TestUrlManager {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		final ArrayList<String> testUrl = new ArrayList<String>();
		final History historyMan = new History();
		
		if(args.length >= 1){
			for(int cc = 0; cc < args.length; cc++){
				testUrl.add( args[cc] );
			}
		}else{
			testUrl.add( "http://www.google.com" );
			testUrl.add( "http://3.211.65.98/FileH/Content/Repository/eBooks/Ecma-357%20Standard%20E4X.pdf" );
			testUrl.add( "http://dsc.discovery.com/news/xml/top-stories.xml" );
			testUrl.add( "http://3.211.65.98/FileH/Content/Repository/eBooks/Sendmail%20Performance%20Tuning%20(Addison%20Wesley).chm" );
			testUrl.add( "http://3.211.65.98/FileH/Content/Repository/wrar362.exe" );
		}
		try{
			final UrlManager urlMan = new UrlManager();
			
			urlMan.addObserver( historyMan );
			
			for(Iterator<String> url = testUrl.iterator(); url.hasNext();){
				urlMan.getContent( url.next() );
				System.out.println( (String) urlMan.getPageContent() );
			}
			
			historyMan.persist();
			
			
		}catch(MalformedURLException mal){
			System.out.println("Invalid URL:" + mal.getMessage());
		}catch(IOException ioe){
			System.out.println("Invalid URL:" + ioe.getMessage());
		}

	}

}
